/* 
 * File:   SegmentaRGB.cpp
 * Author: User007
 * 
 * Created on August 17, 2011, 9:16 PM
 */

#include "SegmentaRGB.h"
#include "ImgMatriz.h"
#include <cv.h>
#include <highgui.h>

SegmentaRGB::SegmentaRGB() {
}

SegmentaRGB::SegmentaRGB(const SegmentaRGB& orig) {
}

SegmentaRGB::~SegmentaRGB() {
}
void SegmentaRGB::SegmentaImg(IplImage* img){
    ImgMatriz im;

    for (int h = 0; h < img->height; h++) {
        for (int w = 0; w < img->width; w++) {
            int b = im.getPixel(img, w, h, 0);
            int g = im.getPixel(img, w, h, 1);
            int r = im.getPixel(img, w, h, 2);

            im.setPixel(b * 2, img, w, h, 0);
            im.setPixel(g * 2, img, w, h, 1);
            im.setPixel(r * 0, img, w, h, 2);
        }
    }
   
    cvSaveImage("output.jpg", img);

    for (int h = 0; h < img->height; h++) {
        for (int w = 0; w < img->width; w++) {
            int b = im.getPixel(img, w, h, 0);
            int g = im.getPixel(img, w, h, 1);
            int r = im.getPixel(img, w, h, 2);

            if (g > 200 && b < 150) {
                im.setPixel(0, img, w, h, 0);
                im.setPixel(0, img, w, h, 1);
                im.setPixel(0, img, w, h, 2);
            } else {
                im.setPixel(255, img, w, h, 0);
                im.setPixel(255, img, w, h, 1);
                im.setPixel(255, img, w, h, 2);
            }
        }
    }

   cvSaveImage("outputBinary.jpg", img);

}
